#include <amxmodx>
#include <umitem>
#include <engine>

new PLUGIN_NAME[] 	= "UM Item: Fall Protection"
new PLUGIN_AUTHOR[] 	= "Cheap_Suit"
new PLUGIN_VERSION[] 	= "1.0"

new bool:g_Falling[33]
new bool:g_FallProtection[33] 
public plugin_init() 
{
	register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
	register_item("Fall Protection", "Take no damage from falling", 2000)
}

public client_connect(id) {
	g_FallProtection[id] = false
}

public Enable_Item(id) {
	g_FallProtection[id] = true
}

public Disable_Item(id) {
	g_FallProtection[id] = false
}

public client_PreThink(id) 
{
	if(!is_user_connected(id) || !is_user_alive(id)) {
		return PLUGIN_CONTINUE
	}
	
	if(!g_FallProtection[id]) {
		return PLUGIN_CONTINUE
	}
	
	if(entity_get_float(id, EV_FL_flFallVelocity) >= 350.0) {
		g_Falling[id] = true
	} else {
		g_Falling[id] = false
	}
	return PLUGIN_CONTINUE
}

public client_PostThink(id) 
{
  	if(!is_user_connected(id) || !is_user_alive(id)) {
		return PLUGIN_CONTINUE
	}
	
	if(!g_Falling[id]) {
		return PLUGIN_CONTINUE
	}
	
	entity_set_int(id, EV_INT_watertype, -3)
	return PLUGIN_CONTINUE
}
